<template>
	<view class="footer">
		<view @click="collection" class="footer-left">
			<u-icon v-if="collect" class="icon nochecked" name="star"></u-icon>
			<u-icon v-else class="icon checked" name="star-fill"></u-icon>
			<view>{{ collect ? "收藏岗位" : "取消收藏" }}</view>
		</view>
		<view class="footer-right">
			<view @click="phone(job.publishTell)" class="btn">
				
				<u-icon name="phone"></u-icon>{{simple1==0?"拨打电话":"联系经纪人"}}
			</view>
			<button @click="jion(job)" class="btn" open-type="contact">
				<u-icon name="edit-pen"></u-icon>在线报名
			</button>
		</view>
	</view>
</template>

<script>
import api from "../../../../../api/routes.js";
export default {
  props: ["job", "jobId","simple1"],

  data() {
    return {
      collect: true,
    };
  },
  onLoad() {
  },
  computed:{
	  
  },

  methods: {
    async collection() {
      if (!uni.getStorageSync("token")) {
        uni.navigateTo({
          url: "/package/pages/components/auth",
        });

        return false;
      } else {
        const res = await this.$myRequest({
          url: api.collect,
          method: "GET",
          data: {
            collectId: this.jobId,
            type: "job",
          },
        });
		console.log(res,'footer');
        if (res.data.code == 0) {
          uni.showToast({
            title: res.data.msg,
            duration: 2000,
          });
          this.collect = !this.collect;
        }
      }
    },
    async phone(phone) {
      if (!uni.getStorageSync("token")) {
        uni.navigateTo({
          url: "/package/pages/components/auth",
        });
        return false;
      }
	  const res = await this.$myRequest({
	    	url: api.myJobCount,
	    	method: "GET",
	    	 data:{},
	  })
	  console.log(res,'foot1');
	  if(res.data.count>0){
		  uni.makePhoneCall({
		    phoneNumber: phone, //仅为示例
		  });
		  
	  }else{
		  wx.showToast({
		  	title: '您至少发布一条求职信息才可拨打电话',
		  	icon: 'none'
		  })				
		  setTimeout(() => {
		  	uni.navigateTo({
		  		url: '/package/pages/release/jobWanted',
		  	});
		  	wx.hideLoading()
		  }, 1500)
	  }

      // uni.makePhoneCall({
      //   phoneNumber: phone, //仅为示例
      // });
    },
    async jion(val) {
      const res = await this.$myRequest({
        url: api.applyJob,
        method: "GET",
        data: {
          jobId: this.jobId,
        },
      });
    },

    async checkIsCollect(val) {
      console.log(val);
      const res = await this.$myRequest({
        url: api.checkIsCollect,
        method: "GET",
        data: {
          collectId: this.jobId,
          type: "job",
        },
      });
      this.collect = !res.data.collectState;
    },
  },
  mounted() {
    this.checkIsCollect();
  },
};
</script>
<style scoped lang="scss">
.footer {
padding-bottom: 0;
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
  height: 50px;
  display: flex;
  align-items: center;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  z-index: 9;

  // z-index: 9;
  &-left {
    flex: 1;
    text-align: center;
    font-size: 11px;
    color: #afb2be;
	height: 50px;
	 background: #fff;

    .icon {
      font-size: 25px;
	  margin-top: 5px;

      &.checked {
        color: #2979ff;
      }
    }
  }

  &-right {
    flex: 2;
    display: flex;
    align-items: center;

    .btn {
      flex: 1;
      height: 50px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 0;
      color: #fff;
      font-size: 14px;

      .u-icon--right {
        padding-right: 5px;
      }

      &:nth-child(1) {
        background: #ef4c36;
      }

      &:nth-child(2) {
        background: #1684fd;
      }
    }
  }
}
</style>
